package proxy;

public class ConnectionDetail {
	public String ip;
	public int localPort;
	public String host;
	public int remotePort;
	public String url;
	public boolean open;
	public boolean ssl = false;
	
	public ConnectionDetail(){
		
	}
	
	public ConnectionDetail(String ip, int localPort, String host, int remotePort, String url, boolean ssl, boolean open) {
		this.ip = ip;
		this.localPort = localPort;
		this.host = host;
		this.remotePort = remotePort;
		this.open = open;
		this.url = url;
	}
	
	public String[] getTableValues(){
		return new String[]{"", ip + ":" +  String.valueOf(localPort), host + ":" +  String.valueOf(remotePort), "http" + (ssl ? "s" : "") + "://" + host + (remotePort == 80 ? "" : ":" + remotePort) + url};
	}
	
	public int hashCode(){
		return ip.hashCode() ^ localPort ^ host.hashCode() ^ remotePort ^ url.hashCode();
	}
	
	public boolean equals(Object obj){
		boolean ret = false;
		if ((obj instanceof ConnectionDetail)){
			ConnectionDetail that = (ConnectionDetail) obj;
			if (that.ip.equals(ip) && that.localPort == localPort && that.host.equals(host) && that.remotePort == remotePort){
				ret = true;
			}
		}
		return ret;
	}
	
	public String toString(){
		return (open ? "Opened " : "Closed ") + ip + ":" + localPort + " --> http" + (ssl ? "s" : "") + "://" + host + (remotePort == 80 ? "" : ":" + remotePort) + url;
	}
}
